<template>
  <Dialog
    class="edit-dialog"
    title="二维码链接"
    :visible.sync="dialogVisible"
    @submit="submit"
    :footer="true"
  >
    <div class="qrcode-box">
      <img :src="imgData" alt="" />
    </div>

    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
    </span>
  </Dialog>
</template>

<script>
import { getCommonQRCode } from "@/api/QRCode";
export default {
  name: "QRCode",
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    roleInfo: {
      type: Object,
      default: {}
    }
  },
  data() {
    return {
      //对话框状态--------------------------------------------
      dialogVisible: this.visible,
      imgData: ""
    };
  },

  watch: {
    //监听对话框状态--------------------------------------------
    dialogVisible(newVal) {
      this.$emit("update:visible", newVal);
    }
  },

  mounted() {
    console.log(this.roleInfo);
    this.getCommonQRCode();
  },
  methods: {
    //确定提交--------------------------------------------
    submit() {
      this.dialogVisible = false;
    },
    // 展示二维码
    getCommonQRCode() {
      const params = {
        uuid: this.roleInfo.uuid
      };
      getCommonQRCode(params).then(res => {
        let QRCode = res.data;
        const blob = new Blob([QRCode]);
        const url = window.URL.createObjectURL(blob);
        this.imgData = url;
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.qrcode-box {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;

  .prt-name {
    width: 100%;
    margin: 20px;
    text-align: center;
    font-size: 18px;
    line-height: 18px;
  }
}
</style>
